home *** CD-ROM | disk | FTP | other *** search
- ;/*
- sc RESOPT IGNORE=73 DATA=NEAR NMINC UCHAR CONSTLIB STREQ STRMERGE NOSTKCHK NOSTDIO OPTIMIZE OPTSIZE mandelbrot.c
- slink from LIB:c.o mandelbrot.o to //Clients/Mandelbrot LIB LIB:scm.lib LIB:sc.lib LIB:amiga.lib /lib/client.lib SC SD STRIPDEBUG NOICONS
- ; To compile for math coprocessor:
- sc DEFINE=MATH881 RESOPT IGNORE=73 DATA=NEAR NMINC UCHAR CONSTLIB STREQ STRMERGE NOSTKCHK NOSTDIO OPTIMIZE OPTSIZE MATH=881 mandelbrot.c
- slink from LIB:c.o mandelbrot.o to //Clients/Mandel881 LIB LIB:scm881.lib LIB:sc.lib LIB:amiga.lib /lib/client.lib SC SD STRIPDEBUG NOICONS
- delete mandelbrot.o
- quit
-
- Mandelbrot 1.3 (Client for BServer)
-
- Copyright © 1994-1995 Luca Viola & Stefano Reksten of 3AM - The Three Amigos!!!
- All rights reserved.
-
- Reworked and compiled also for 68881 as Massimo Capanni asked.
- */
-
- #include <exec/types.h>
- #include <intuition/intuition.h>
- #include <graphics/gfxbase.h>
-
- #include <proto/exec.h>
- #include <proto/intuition.h>
- #include <proto/graphics.h>
- #include <stdlib.h>
- #include <math.h>
- #include <time.h>
-
- #include "/include/client.h"
-
- #ifndef MATH881
- char *ver = "$VER: Mandelbrot 1.2 "__AMIGADATE__;
- #else
- char *ver = "$VER: Mandel881 1.2 "__AMIGADATE__;
- #endif
-
- struct IntuitionBase *IntuitionBase;
- struct GfxBase *GfxBase;
- struct Library *BitMapBase;
-
- struct DisplayIDInformation *dinfo;
- UBYTE command;
- BOOL stillBlanking;
-
- #define XOFF 0
- #define YOFF 0
-
- #define RISX 240
- #define RISY 240
- #define PLANES 4
- #define MAXITER 32
- #define COLORS (1 << PLANES)
-
- /* function prototypes */
-
- void Mandel( void );
- void DrawMandel( void );
-
- /* Intuition global structures */
-
- struct IntuitionBase *IntuitionBase;
- struct GfxBase *GfxBase;
- struct Screen *thescreen;
- struct RastPort *rport;
- struct ViewPort vport;
- struct BitMap *bitmap;
- ULONG *table;
-
- UBYTE colors[]=
- {
- 0,0,0, 1,1,15, 2,2,14, 3,3,13, 4,4,12, 5,5,11, 6,6,10, 7,7,9,
- 8,8,8, 9,9,7, 10,10,6, 11,11,5, 12,12,4, 13,13,3, 14,14,2, 15,15,1
- };
-
-
- void Mandel()
- {
- UBYTE n, *col, brightness = GETBRIGHTNESS(dinfo);
- ULONG displayID = DISPLAYID(dinfo);
- UWORD rwidth;
- struct Rectangle *rect = GETTXTOSCANRECT(dinfo);
-
- rwidth = RECTANGLEWIDTH(rect);
-
- if ( !CheckAA() )
- {
- if ( displayID & SUPERHIRES )
- {
- displayID &= ~SUPERHIRES;
- displayID |= HIRES;
- rwidth >>= 1;
- }
- }
-
- if ( thescreen = (struct Screen *)OpenScreenTags( NULL,
- SA_Left, (rwidth - RISX)>>1,
- SA_DisplayID, displayID,
- SA_Width, RISX,
- SA_Height, RISY,
- SA_Depth, PLANES,
- SA_Quiet, TRUE,
- SA_Overscan, OSCAN_TEXT,
- TAG_DONE ) )
- {
- col = colors;
- for ( n = 0; n < 3<<PLANES; n++ )
- {
- *col = *col * brightness/100;
- col++;
- }
-
- rport=&(thescreen->RastPort);
- vport=thescreen->ViewPort;
- col= colors;
- for ( n = 0; n < 1<<PLANES; n++ )
- SetRGB4( &vport, n, *col++, *col++, *col++ );
- DrawMandel();
- CloseScreen( thescreen );
- }
- else
- SendClientMsg( ACTION_FAILED );
- }
-
-
- void DrawMandel()
- {
- double quadsize;
- double temp,xr,yr,d,vx,vy,x1real,y1imm,x2real,y2imm,gapx,gapy;
- UWORD loop,x,y,risx,risy;
-
- SpritesOff();
-
- srand48( (unsigned int)time( NULL ) );
-
- stillBlanking = TRUE;
-
- risx=RISX;
- risy=RISY;
-
- while( stillBlanking )
- {
- quadsize = 3.4 * drand48();
- x1real = -2.2 * drand48();
- x2real = x1real + quadsize;
- y1imm = -1.7 * drand48();
- y2imm = y1imm + quadsize;
-
- gapx = ( x2real - x1real ) / risx;
- gapy = ( y1imm - y2imm ) / risy;
- vy = y2imm;
-
- for ( y = 0; y < RISY; y++ )
- {
- vy = vy + gapy;
- vx = x1real;
- for( x = 0; x < RISX && stillBlanking; x++ )
- {
- vx = vx + gapx;
- xr = 0; yr = 0;
- loop = 0;
-
- do
- {
- loop++;
- temp = ( (xr*xr) - (yr*yr) ) + vx;
- yr = ( 2.0F * xr * yr ) + vy;
- xr = temp;
- d = xr * xr + yr * yr;
- if ( d > 4.0F )
- {
- SetAPen( &(thescreen->RastPort), loop%COLORS+1 );
- WritePixel( &(thescreen->RastPort), x, y );
- loop=MAXITER;
- }
- stillBlanking = STILL_BLANKING;
- }
- while(loop!=MAXITER && stillBlanking );
-
- if ( stillBlanking && ( d < 4.0F ) )
- {
- SetAPen( &(thescreen->RastPort), 0 );
- WritePixel( &(thescreen->RastPort), x, y );
- }
- }
- }
- }
- SpritesOn();
- }
-
-
- void __main( char *line )
- {
- if ( IntuitionBase = (struct IntuitionBase *)OpenLibrary( "intuition.library", 37L ) )
- {
- if ( GfxBase = (struct GfxBase *)OpenLibrary( "graphics.library", 37L ) )
- {
- if ( dinfo = OpenCommunication() )
- {
- Mandel();
- CloseCommunication( dinfo );
- }
- CloseLibrary( (struct Library *)GfxBase );
- }
- CloseLibrary( (struct Library *)IntuitionBase );
- }
- }
-